package com.xlh.dao.course.helper;

import cn.hutool.core.collection.CollectionUtil;
import com.xlh.dao.course.ChapterMapper;
import com.xlh.pojo.course.Chapter;
import com.xlh.pojo.course.ChapterExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cfz
 */
@Repository
public class ChapterMapperHelper {

    @Autowired
    private ChapterMapper chapterMapper;

    public Chapter getChapterByCondition(Long chapterId){

        ChapterExample example = new ChapterExample();
        example.createCriteria().andIdEqualTo(chapterId).andDeletedEqualTo(false);
        List<Chapter> chapters = chapterMapper.selectByExample(example);
        if(CollectionUtil.isNotEmpty(chapters)){
            return chapters.get(0);
        }
        return null;
    }

    public List<Chapter> getChapterByCondition(List<Long> chapterIds){

        ChapterExample example = new ChapterExample();
        example.createCriteria().andIdIn(chapterIds).andDeletedEqualTo(false);
        List<Chapter> chapters = chapterMapper.selectByExample(example);
        return chapters;
    }




}
